package leetcode.editor.cn;
//[191]位1的个数
public class NumberOf1Bits191{
public static void main(String[] args) {
   Solution solution = new NumberOf1Bits191().new Solution();
   
}

  //leetcode submit region begin(Prohibit modification and deletion)
class Solution {
    //	执行耗时:0 ms,击败了100.00% 的Java用户
    //	内存消耗:39.6 MB,击败了78.32% 的Java用户
    public int hammingWeight0(int n) {
        int count = 0;
        while (n!=0){
            if ((n&1) == 1){
                count++;
            }
            n = n>>1;//最长 需要 32次
        }
        return count;
    }

    //	执行耗时:0 ms,击败了100.00% 的Java用户
    //	内存消耗:39.7 MB,击败了56.52% 的Java用户
   public int hammingWeight(int n) {
        int count = 0;
        while (n!=0){
             count++;
            n = n & (n-1);//需要 1 的次数。 但是需要计算 n-1
        }
        return count;
    }


}
//leetcode submit region end(Prohibit modification and deletion)

}